<?php
	class page {
		function page($site_pages_id)
		{
			if($site_pages_id)
			{
				$st="SELECT * FROM site_pages WHERE site_pages_id='$site_pages_id'";
				$rc = mysql_query($st) or die(mysql_error());
				$a_rw=mysql_fetch_array($rc);
				$this->site_pages_id=$a_rw['site_pages_id'];
				$this->page_content=$a_rw['page_content'];
				$this->content=$a_rw['content'];
			}
		}

		function add_page($conn) {
			$sql = "INSERT INTO `site_pages` ( `site_pages_id` , `page_name` , `content` ) VALUES ('', '".$_POST['txt_page_name']."', '".$_POST['txtar_page_content']."');";
			mysql_query($sql);
			$current_id=mysql_insert_id($conn);
			return $current_id;
		}

		function edit_page() {
			$sql = "UPDATE site_pages SET page_name='".addslashes($this->page_name)."',content='".addslashes($this->content)."' WHERE site_pages_id='".$this->site_pages_id."'";
			mysql_query($sql);
			$mesg = "Page contents has been modified successfully.";
			return $mesg;
		}
		function list_pages() {
			$sql = "SELECT site_pages_id,page_name FROM site_pages";
			$qR = mysql_query($sql);
			while($row=mysql_fetch_assoc($qR)) {
				$data[] = $row;
			}
			return $data;
		}

		function get_page_by_id() {
			$sql = "SELECT * FROM site_pages WHERE site_pages_id='".$this->site_pages_id."'";
			$qR = mysql_query($sql);
			return $qR;
		}

		function delete_page() {
			$sql = "DELETE FROM site_pages WHERE site_pages_id='".$_REQUEST['id']."'";
			mysql_query($sql);
		}
	}
?>